package com.gouaixin.bee.beeframework2.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AbsListView;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.gouaixin.bee.beeframework2.R;
import com.gouaixin.bee.beeframework2.tool.mLog;
import com.lidroid.xutils.BitmapUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

import java.util.ArrayList;
import java.util.List;

import cn.bmob.v3.datatype.BmobFile;

/**
 * Created by Administrator on 2015/3/30.
 */
public class XiangceAdapter extends BaseAdapter {

    Context context;
    List<BmobFile> datas = new ArrayList<BmobFile>();
    ImageLoader imageLoader;

    int qian=1;//固定显示项

    public XiangceAdapter(Context context) {
        this.context = context;
        imageLoader=ImageLoader.getInstance();
    }

    public void setData(List<BmobFile> data) {
        datas = data;
    }

    @Override
    public int getCount() {
        return datas.size()+qian;
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

//        final ImageView mView = (ImageView) LayoutInflater.from(context).inflate(R.layout.grideview_image,
//                null);
        final TextView mView = new TextView(context);

        AbsListView.LayoutParams param = new AbsListView.LayoutParams(
                ViewGroup.LayoutParams.MATCH_PARENT,
                160);
        mView.setLayoutParams(param);

//        mView.setBackgroundResource(R.drawable.mylogo);

//        if (datas.size() != 0) {
            mLog.e("相册图片个数:" + datas.size());

            if(position==0){
                mView.setBackgroundResource(R.drawable.btn_upload_photo_nor);
            }else{
                BmobFile micon = datas.get(position-qian);
                if (micon != null) {
                    String url = micon.getFileUrl(context);
                    mLog.e("相册图片url:" + url);
//                ImageLoader.getInstance().displayImage(url, icon);
                    BitmapUtils bitmapUtils=new BitmapUtils(context);
                    bitmapUtils.display(mView,url);
                }

            }
//        }


        return mView;
    }
}
